<template>
    <view>
		<xmInfo
		  :projectno="dataInfo.projectcode"
		  :projectname="dataInfo.name"
		></xmInfo>
		
        <form>
      
            <!-- {{ dataInfo.jieshui_type  + picker[dataInfo.jieshui_type]}} -->
            <view class="cu-form-group ">
                <view class="title"><text class="cuIcon-favorfill text-xs text-red"></text>签证类型</view>
                <view>
					<js-radio  v-model="dataInfo.istemporary" dict-type="zf_visa_type" style="text-align: right;"></js-radio>
                    <!-- <js-select v-model="dataInfo.istemporary" dict-type="zf_visa_type" style="text-align: right;"></js-select> -->
                </view>
            </view>
			<view class="cu-bar bg-white">
			    <view class="title action"><text class="cuIcon-favorfill text-xs text-red"></text>描述</view>
			   <!-- <view>
					<input placeholder="请输入描述" name="input" v-model="dataInfo.describe"  class="input-align"></input>
				</view> -->
			</view>
			<view class="cu-form-group">
			  <textarea
			    v-model="dataInfo.describe"
				placeholder-class="line"
				type="text"
			    placeholder="请输入描述"
			  ></textarea>
			</view>
            
            <view class="cu-form-group" style="min-height: 0px;"></view>
            <view class="cu-bar bg-white">
                <view class="action"><text class="cuIcon-favorfill text-xs text-red"></text>现场图片</view>
            </view>
            <view class="cu-form-group"><js-uploadfile 
			 :deletable="!dataInfo.id" :customBtn="dataInfo.id"
			 v-model="dataInfo.dataMap"  :biz-key="dataInfo.id"   biz-type="PmVisaXc_image" ></js-uploadfile></view>

            <view class="cu-form-group" style="min-height: 0px;"></view>
            <view class="cu-bar bg-white">
                <view class="action"><text class="cuIcon-favorfill text-xs text-red"></text>签证图片</view>
            </view>
            <view class="cu-form-group"><js-uploadfile
			  :deletable="!dataInfo.id" :customBtn="dataInfo.id"
			  v-model="dataInfo.dataMap"  :biz-key="dataInfo.id"   biz-type="PmVisaQz_image" ></js-uploadfile></view>
            

			<view class="cu-card margin radius">
			  <!-- <view class="cu-form-group margin-top">
			      <view class="title">项目编号</view>
			      <view>{{ dataInfo.projectcode }}</view>
			  </view>
			  <view class="cu-form-group ">
			      <view class="title">项目名称</view>
			      <view>{{ dataInfo.name }}</view>
			  </view> -->
			  <view class="cu-form-group ">
			      <view class="title">上传人</view>
			      <view>{{ dataInfo.operator }}</view>
			  </view>
			  <view class="cu-form-group ">
			      <view class="title">上传时间</view>
			      <view>{{ dataInfo.createDate }}</view>
			  </view>
			</view>
              
            
          <view style="height: 80px" v-if="!dataInfo.id"></view>
            <view class="btn-group cu-bar foot " v-if="!dataInfo.id">
                <button class="cu-btn bg-blue shadow-blur" @tap="confirm">提交</button>
            </view>
        </form>
        
    </view>
</template>
<script>
import xmInfo from "@/pages/zfgs/index/componetns/xmInfo.vue";
import {hasPermission} from '@/common/fire.js'
export default {
  components: {
    xmInfo
  },
  data() {
    return {
      switchA: false,
      date: "2024-03-12",
      uploadOptions: {},
      index: -1,
      modalName: null,
      modalNameDetail: null,
      showAddDetail: false,
      dataInfo: {},
      showButton: true,
      addflag: hasPermission('btn:add:xianchangqianzheng'),
      editflag: hasPermission('btn:edit:xianchangqianzheng'),
      isSubmitting: false,
    };
  },
  onLoad(e) {
    if (!!e.id) {
      this.showButton = true;
      this.getVisaPmVisaForm(e.id);
      this.dataInfo.id = e.id;
    }
    if (!!e.xm) {
      this.showButton = true;
      console.log(e.xm);
      this.dataInfo = JSON.parse(e.xm);
      this.dataInfo.operator = this.vuex_user.userName;
      this.dataInfo.projectcode = this.dataInfo["projInfo.projectno"];
      this.dataInfo.name = this.dataInfo["projInfo.projectname"];
      console.log(this.dataInfo);
      //   巡检人
    }
  },
  methods: {
    confirm() {
      if(!this.dataInfo.istemporary){
        this.$u.toast("签证类型必选");
        return;
      }
      console.log(this.dataInfo, "this.dataInfo");
      if (!this.dataInfo.dataMap || !this.dataInfo.dataMap.PmVisaXc_image) {
        this.$u.toast("现场图片必传");
        return;
      }
      if (!this.dataInfo.dataMap || !this.dataInfo.dataMap.PmVisaQz_image) {
        this.$u.toast("签证图片必传");
        return;
      }
      if(!this.dataInfo.describe){
        this.$u.toast("描述必填");
        return;
      } 
      if (this.isSubmitting) {
        return;
      } else {
        this.isSubmitting = true;
        try {
          this.$u.api.zfgs.visaPmVisaSave(this.dataInfo).then((res) => {
            if (res.result == "true") {
              this.$u.toast("保存成功");
              const itemContent = {
                projectno: this.dataInfo.projectcode,
                projectname: this.dataInfo.name,
              };
              setTimeout(() => {
                // uni.navigateTo({
                //   url:
                //     "/pages/zfgs/design/visa/pmVisa/list?item=" +
                //     JSON.stringify(itemContent),
                // });
				uni.navigateBack({
				  delta: 1,
				});
              }, 500);
            } else {
              this.$u.toast(res.message);
            }
          });
        } catch (error) {
          this.$u.toast(error.message);
        } finally {
          this.isSubmitting = false;
        }
      }
    },
    getVisaPmVisaForm(id) {
      this.$u.api.zfgs
        .visaPmVisaForm({
          id: id,
        })
        .then((res) => {
          this.dataInfo = res.pmVisa;
          this.dataInfo.istemporary = this.dataInfo.istemporary + '';
        });
    },
    SwitchA(e) {
      // this.switchA = e.detail.value
    },
    DateChange(e) {
      this.date = e.detail.value;
    },
    textareaAInput(e) {
      this.dataInfo.dmark = e.detail.value;
    },
    addDetail() {
      this.showAddDetail = true;

      this.modalNameDetail = "bottomModal";

      console.log(this.modalNameDetail);
    },
    modalNameDetailEmit(e) {
      this.modalNameDetail = e;
    },

    ViewImage(imageList, e) {
      uni.previewImage({
        urls: imageList,
        current: e.currentTarget.dataset.url,
      });
    },
    DelImg(e) {
      uni.showModal({
        title: "",
        content: "确定要删除吗？",
        cancelText: "取消",
        confirmText: "确认",
        success: (res) => {
          if (res.confirm) {
            console.log(
              res.confirm,
              this.dataInfo.dImageList,
              e,
              this.dataInfo.dImageList[e.currentTarget.dataset.index]
            );
            // this.dataInfo.dImageListst.splice(e.currentTarget.dataset.index, 1)
            // if (this.dataInfo.dImageListst) {
            //     console.log(e.currentTarget.dataset.index,this.dataInfo.dImageListst,'e====')
            //     this.dataInfo.dImageListst.splice(e.currentTarget.dataset.index, 1);
            // }
            // this.$set(this.dataInfo.dImageListst, e.currentTarget.dataset.index,1)
            // this.dataInfo.dImageListst.splice(e.currentTarget.dataset.index, 1);
            this.$delete(
              this.dataInfo.dImageListst,
              e.currentTarget.dataset.index
            );
          }
        },
      });
    },
    ChooseImage() {
      uni.chooseImage({
        count: 4, //默认9
        sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
        sourceType: ["album"], //从相册选择
        success: (res) => {
          if (this.dataInfo.shiYaFile.length != 0) {
            this.dataInfo.shiYaFile = this.dataInfo.shiYaFile.concat(
              res.tempFilePaths
            );
          } else {
            this.dataInfo.shiYaFile = res.tempFilePaths;
          }

          console.log(this.dataInfo, "this.dataInfo");
          this.$u.toast("上传成功");
        },
      });
    },
    PickerChange(e) {
      console.log(e.detail.value);
      this.dataInfo.istemporary = e.detail.value;
      this.$forceUpdate();
    },
    RadioChange(e) {
      this.dataInfo.jieshui_guandao = e.detail.value;
    },
    PickerChangeArea(e) {
      this.dataInfo.jieshui_area = e.detail.value;
    },
  },
};
</script>
<style lang="scss" scoped>
.action {
  color: #303133;
}
.title {
  flex-shrink: 0;
}
.text-sl {
  font-size: 22px !important;
}
.cu-bar {
}
.cu-btn {
  font-size: 16px;
  height: 40px;
}
.foot {
  min-height: 80px;
  z-index: 997;
  background: #fff;
}
.green {
  color: green;
}
.input-align {
  text-align: right;
}
::v-deep .u-input__input {
  width: 100%;
  text-align: right !important;
}
.text-xs {
  font-size: 18rpx !important;
}
</style>